package com.jstower.modules.sample.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import com.jstower.modules.sample.dao.SampleDAO;
import com.jstower.modules.sample.entity.Sample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Description:
 * Author: chenshuai
 * Project: js-webapp
 * Version: V1.0
 * Create Date: 16/2/29
 */
@Service
public class SampleServiceImpl implements ISampleService{

    @Autowired
    private SampleDAO sampleDAO;

    /**
     * 分页查询sample数据
     * @param page      当前页码
     * @param pageSize  页面大小
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo listSamplePage(int page, int pageSize) throws Exception{
        Map paramMap = Maps.newHashMap();

        String sortString = "create_time asc,group_code desc";//如果你想排序的话逗号分隔可以排序多列
        PageHelper.startPage(page,pageSize,sortString);
        List<Sample> list = sampleDAO.getPageList(paramMap);
        //用PageInfo对结果进行包装
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<Sample> findSample(Map paramMap) throws Exception{

        List<Sample> sampleList = sampleDAO.find(paramMap);
        return sampleList;
    }
}
